const getVueTemplate = (componenetName) => `
<div class="pageBox clearfix page-panel">
<el-pagination
  background
  @current-change="handleCurrentChange"
  :current-page.sync="${componenetName}.pageNo"
  :page-size="${componenetName}.pageSize"
  layout="total, prev, pager, next, jumper"
  :total="${componenetName}.totalRecord"
>
</el-pagination>
</div>`;
const getDataTemplate = (componenetName) => `${componenetName}: {
  pageNo: 1,
  pageSize: 15,
  totalRecord: 0,
},`;
const getModifyTemplate = (componenetName) => [
  //template
  {
    repeatReg: new RegExp(
      `:current-page\\.sync=['"]${componenetName}\\.pageNo['"]`
    ),
    targetReg: /(<\/\S*>[\s]*<\/template>[\s]*?<script>)/,
    tagetReplace: `${getVueTemplate(componenetName)}\n$1`,
  },
  // 定义data
  {
    repeatReg: new RegExp(`${componenetName}:\\s*\{`),
    targetReg: /data\(\)\s*{([\s]*?)return[\s]*{/,
    tagetReplace: `data\(\) {$1return {
     ${getDataTemplate(componenetName)} `,
  },
  {
    // methods
    repeatReg: /handleCurrentChange\(/,
    targetReg: /methods:\s*{/,
    tagetReplace: `methods: {
      handleCurrentChange(page) {
        this.tablePag.pageNo = page;
        //this.params.pageNo = page;
        //this.handleGetData();
      },`,
  },
];
module.exports = {
  getModifyTemplate,
};
